package com.supreme.studyserver.controller;

import com.supreme.commonboot.utils.AjaxResp;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "jdbc")
public class JDBCController {

//    @Resource
//    private JdbcTemplate jdbcTemplate;

    @Resource
//    @Qualifier("primaryJdbcTemplate")
    protected JdbcTemplate primaryJdbcTemplate;

    @Resource
//    @Qualifier("secondaryJdbcTemplate")
    protected JdbcTemplate secondaryJdbcTemplate;

    @Resource
//    @Qualifier("oracleJdbcTemplate")
    protected JdbcTemplate oracleJdbcTemplate;

    @GetMapping(value = "/selectTest")
    public AjaxResp selectTest() {
        String sql = "select * from test";
        final List<Map<String, Object>> queryForList = primaryJdbcTemplate.queryForList(sql);
        return AjaxResp.instance(queryForList);
    }

    @GetMapping(value = "/selectSecondary")
    public AjaxResp selectSecondary() {
        String sql = "select * from secondary";
        final List<Map<String, Object>> queryForList = secondaryJdbcTemplate.queryForList(sql);
        return AjaxResp.instance(queryForList);
    }

    @GetMapping(value = "/selectOracleTest")
    public AjaxResp selectOracleTest() {
        String sql = "select * from TBL_TEST";
        final List<Map<String, Object>> queryForList = oracleJdbcTemplate.queryForList(sql);
        return AjaxResp.instance(queryForList);
    }
}
